﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfAutoArray: IEnumerable
    {
        public PdfArray BaseArray;
        public object[] CacheArray;

        public PdfAutoArray(PdfArray baseArray)
        {
            this.BaseArray = baseArray;
            this.CacheArray = new object[Count];
        }

        public int Count { get { return BaseArray.Count; } }

        public object this[int index]
        {
            get
            {
                object value = CacheArray[index];
                if (value == null)
                    CacheArray[index] = value = PdfObjectResolver.Resolve(BaseArray[index]);

                return value;
            }
        }

        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < Count; i++)
                yield return this[i];
        }
    }
}
